/**
 * $Id$
 *
 * @author Noritaka Horio<holy.shared.design@gmail.com>
 * @copyright 2009 Noritaka Horio all rights resrved. 
 * @license The MIT License
 * @version $Revision$
 * @since
 */

var Processing = new Class({

	Implements: [Options, Events],

	options: {
		"id": "processing",
		"swf": "app:/libraries/processing/processing.swf"
	},

	initialize: function(container, options) {
		this.setOptions(options);
		this.container = $(container);
		this.buildStructure();
		this.setEvents();
	},

	setEvents: function() {
		ProcessingAS.onLoad = function () {
			this.Processing = $(this.options.id);
			this.Processing.start();
			this.fireEvent("load");
		}.bind(this);

		ProcessingAS.onResize = function (w, h) {
			this.Processing.width = w;
			this.Processing.height = h;
			this.fireEvent("resize", [w, h]);
		}.bind(this);
	},

	buildStructure: function() {
		this.Processing = new Element("object", {
			"id": this.options.id,
			"type": "application/x-shockwave-flash",
			"width": "0",
			"height": "0",
			"data": this.options.swf
		});

		var param = new Element("param", {
			"name": "allowScriptAccess",
			"value": "always"
		});
		param.inject(this.Processing);

		this.Processing.inject(this.container);
	},

	run: function(code, images) {
		this.Processing.run(code, images);
	}
});
